import {
  getSearchList,
  getTagList,
  getTaskList,
  findPersonByPic,
  findPerson,
  addToBase
} from "@/api/search/search";
import { diffTime } from "@/common/config/index.js";
export default {
  data() {
    return {
      VideoPhotoData: {
         searchFrom: 'search',
         preCards: [],
         cards:  [],
         persons:  [],
         activeName: "pic",
         page: 1,
         size: 30,
         pageSizeOption: [30, 60, 120],
         alarmlevel:[],
         dictionary:  {},
         monitorLevel: [],
         queryAlarmlevel:  [],
         inputValue: '',
         searchTime:[],
         showType:'search',
         tabs:[],
         blackList:[],
         selectBlacks: [],
         whiteList:  [],
         selectWhites:  [],
         queryTabs:  [],
         compareTabs: [],
         tasks: [],
         queryTasks: [],
         treeNodes:[],
         total:0,
         tabsForUploadImg:  [],
         picUrl:  "",
         threshold: 60,
         activeCard: "",
         uploadImg: "",
         captureId: "",
         compareNum:  "",
         compTargetId: "",
         compTargetType:"1",
         rightSectionDisplay: false,
         scrollContainDom: '',
         uploadDiaplay: false,
         uploadType: false,
         dataSource: 'camera',
         collection: '',
         isComparison:false,
         thatSortList:'asc'
      },
      isCardShow:true,
    }
  },
  created() {
    
   
  },
  methods: {
  clearStatus() {
    //this.cards = [];
    this.VideoPhotoData.page = 1;
    this.VideoPhotoData.size = 60;
    this.VideoPhotoData.pageSizeOption = [30, 60, 120]
    this.VideoPhotoData.alarmlevel = [];
    this.VideoPhotoData.inputValue = "";
    this.VideoPhotoData.showType = "search";
  },

  // 列表数据
  async querySearchList() {
    this.VideoPhotoData.cards = []
    this.VideoPhotoData.preCards = []
    var param = {
      page: this.VideoPhotoData.page,
      size: this.VideoPhotoData.size,
      searchTime: this.VideoPhotoData.searchTime,
      alarmlevel: this.VideoPhotoData.queryAlarmlevel,
      inputValue: this.VideoPhotoData.inputValue,
      tabs: this.VideoPhotoData.queryTabs,
      tasks: this.VideoPhotoData.queryTasks,
      treeNodes: this.VideoPhotoData.treeNodes,
      dataSource:this.VideoPhotoData.dataSource,
      collection:this.VideoPhotoData.collection,
      sort:this.VideoPhotoData.thatSortList,
    }
    if (this.VideoPhotoData.searchFrom == 'cluster') {
      param.isAll = true
    }
    const rsp = await getSearchList(param);
    if (rsp && rsp.success) {
      this.VideoPhotoData.cards.length = 0 // 清两次，第一次是为了点完之后不会出现之前数据的残影，这次是为了防止因为异步问题两次请求会出现双倍数据的问题
      this.VideoPhotoData.preCards.length = 0
      if (rsp.data.datalist) {
        rsp.data.datalist.forEach(element => {
          element.ownerPage = this.VideoPhotoData.page
          element.list[0].picDate=diffTime(element.list[0].picDate)
          // console.log(element.list[0].picDate,"看看是啥")
          // debugger
          this.VideoPhotoData.cards.push(element);
        });
        // 是否展示比对详情
        // if(rsp.data.datalist[0].list[0].baseInfo){
          // this.VideoPhotoData.isComparison=true
        // }else{
          // this.VideoPhotoData.isComparison=false
        // }
      }
      console.log(this.VideoPhotoData.cards,"卡片")
      this.VideoPhotoData.total = rsp.data.total;
      this.productPagerOptions.totalCount=rsp.data.total;
    }
  },

  async findPerson() {
    this.VideoPhotoData.cards = []
    var param = {
      page: this.VideoPhotoData.page,
      size: this.VideoPhotoData.size,
      // searchTime: this.VideoPhotoData.searchTime,
      // alarmlevel: this.VideoPhotoData.queryAlarmlevel,
      // inputValue: this.VideoPhotoData.inputValue,
      // tabs: this.VideoPhotoData.queryTabs,
      // treeNodes: this.VideoPhotoData.treeNodes,
      picUrl: this.VideoPhotoData.picUrl,
      // databases: this.VideoPhotoData.compareTabs, 
      threshold: this.VideoPhotoData.threshold,
      // isAll: this.VideoPhotoData.searchFrom == "cluster" ? true : false
    }
    const rsp = await findPersonByPic(param);
    if (rsp && rsp.success) {
        if(rsp.data.list.length===0){
          this.$message.error("未查询到此人信息")
        }else{
          this.$message.success("查询成功")
          this.VideoPhotoData.cards=rsp.data.list
        }
        console.log(this.VideoPhotoData.cards,"看看上")
      // console.log(rsp,"rsp")
      // rsp.data.list.forEach(element => {
      //   var obj = {
      //     activeObject: (element),
      //     list: []
      //   }
      //   // debugger  
      //   element.ownerPage = this.VideoPhotoData.page
      //   element.picDate=diffTime(element.picDate)
      //   obj.list.push((element))
      //   // this.VideoPhotoData.cards.push(obj)
      //   this.VideoPhotoData.cards=obj
      //   console.log(this.VideoPhotoData.cards,"看看obj")
      // });
      
     
      this.VideoPhotoData.total = rsp.data.total
      this.productPagerOptions.totalCount=rsp.data.total;
      this.VideoPhotoData.compareNum = rsp.data.compareNum
      this.isCardShow=false;
      this.$nextTick(()=>{
        this.isCardShow=true;
        this.$forceUpdate()
      })
      // console.log(this.VideoPhotoData.total,'2221')
    }
  },
  async findPerson2() {
    // 111
    this.VideoPhotoData.cards = []
    var compType = this.VideoPhotoData.compTargetType == "1" ? 1 : 0
    let param
    if (this.VideoPhotoData.searchFrom == "cluster") {
      param = {
        page: this.VideoPhotoData.page,
        size: this.VideoPhotoData.size,
        // searchTime: this.VideoPhotoData.searchTime,
        picUrl: this.VideoPhotoData.picUrl,
        // alarmlevel: this.VideoPhotoData.queryAlarmlevel,
        // inputValue: this.VideoPhotoData.inputValue,
        tasks: this.VideoPhotoData.queryTasks,
        // treeNodes: this.VideoPhotoData.treeNodes,
        compTargetId: this.VideoPhotoData.compTargetId,
        compTargetType: compType,
        // databases: this.VideoPhotoData.compareTabs,
        threshold: this.VideoPhotoData.threshold,
        // isAll: true
      }
    } else {
      param = {
        page: this.VideoPhotoData.page,
        size: this.VideoPhotoData.size,
        searchTime: this.VideoPhotoData.searchTime,
        picUrl: this.VideoPhotoData.picUrl,
        alarmlevel: this.VideoPhotoData.queryAlarmlevel,
        inputValue: this.VideoPhotoData.inputValue,
        tasks: this.VideoPhotoData.queryTasks,
        treeNodes: this.VideoPhotoData.treeNodes,
        compTargetId: this.VideoPhotoData.compTargetId,
        compTargetType: compType,
        // databases: this.VideoPhotoData.compareTabs,
        threshold: this.VideoPhotoData.threshold,
      }
    }
    const rsp = await findPersonByPic(param);
    if (rsp && rsp.success) {
      rsp.data.list.forEach(element => {
        var obj = {
          activeObject: (element),
          list: []
        }
        element.ownerPage = this.VideoPhotoData.page
        obj.list.push((element))
        this.VideoPhotoData.cards.push(obj)
      });

      this.VideoPhotoData.total = rsp.data.total
      this.productPagerOptions.totalCount=rsp.data.total;
      this.VideoPhotoData.compareNum = rsp.data.compareNum
    }
  },
  async findPersonByPage() {
    this.VideoPhotoData.cards = []
    var param = {
      page: this.VideoPhotoData.page,
      size: this.VideoPhotoData.size,
      // searchTime: this.VideoPhotoData.searchTime,
      // alarmlevel: this.VideoPhotoData.queryAlarmlevel,
      // inputValue: this.VideoPhotoData.inputValue,
      tasks: this.VideoPhotoData.queryTasks,
      // treeNodes: this.VideoPhotoData.treeNodes,
      picUrl: this.VideoPhotoData.picUrl,
      // databases: this.VideoPhotoData.compareTabs,
      compareNum: this.VideoPhotoData.compareNum,
      threshold: this.VideoPhotoData.threshold,
      // isAll: this.VideoPhotoData.searchFrom == "cluster" ? true : false,
      collection:this.VideoPhotoData.collection
    }
    const rsp = await findPerson(param);
    console.log(rsp,"看看数据是是是")
    if (rsp && rsp.success) {
      rsp.data.totalList.forEach(element => {
        var obj = {
          activeObject: (element),
          list: []
        }
        element.ownerPage = this.VideoPhotoData.page
        obj.list.push((element))
        this.VideoPhotoData.cards.push(obj)
      });
      this.VideoPhotoData.total = rsp.data.total
    }
  },
  async queryTagList() {
    const rsp = await getTagList({});
    this.VideoPhotoData.tabsForUploadImg.splice(0, this.VideoPhotoData.tabsForUploadImg.length)
    if (rsp && rsp.success) {
      var arr1 = new Array
      // if(rsp.data){
      //   arr1 = rsp.data.filter(i => {
      //     if (i.status === 1) {
      //       i.title = i.title + '(已删除)'
      //       return i
      //     }
      //   });
      //   this.VideoPhotoData.tabs = rsp.data.filter(function (i) {
      //     if (i.status !== 1) {
      //       return i
      //     }
      //   })
      //   this.VideoPhotoData.tabs.push(...arr1)
      // }
      if(rsp.data){
        arr1 = rsp.data.filter(function (i) {
          if (i.status !== 1 && i.bwType==='2') {
            return i
          }
        })
        this.VideoPhotoData.tabs = rsp.data.filter(function (i) {
          if (i.status !== 1 && i.bwType==='1') {
            return i
          }
        })
        this.VideoPhotoData.tabs.push(...arr1)
      }
    } else {
      // this.$notify({
      //   title: "失败",
      //   message: "检索数据查询失败！",
      //   type: "warning"
      // });
    }
  },

  async queryTaskList() {
    let params = {};
    if (this.VideoPhotoData.searchFrom == 'cluster') {
      params.isPlatform = 1
    }
    // console.log(params)
    const rsp = await getTaskList(params);
    if (rsp && rsp.success) {
      this.VideoPhotoData.tasks = rsp.data;
    
      // rsp.data.forEach(element => {
      //   this.VideoPhotoData.tasks.push((element));
      // });
      let taskNames = [];
      this.VideoPhotoData.tasks = [];

      rsp.data.forEach((d) => {
        if (taskNames.indexOf(d.name) < 0) {
          taskNames.push(d.name);
          this.VideoPhotoData.tasks.push(d)
        } else {
          let repeatOne = this.VideoPhotoData.tasks.find((one) => one.name == d.name);
          repeatOne['id'] += `,${d.id}`;
          repeatOne['isDelete'] = repeatOne['isDelete'] && d.isDelete
        }
      });
    }
  },

   queryDictionary() {
    // const rsp = await getAlarmLevel({});
    // console.log(rsp,"事件等级")
    // if (rsp && rsp.success) {
    //   this.VideoPhotoData.dictionary = rsp.data;
    // }
    this.VideoPhotoData.dictionary.ALARMLEVEL=[
      {
          children: [],
          description: "报警等级（一级）",
          id: "B86741A6-1C9E-880F-1A27-02C137563F08",
          name: "一级",
          parent_id: "0",
          sort: 1,
          type: "ALARMLEVEL",
          value: "1"
      },
      {
          children: [],
          description: "报警等级（二级）",
          id: "B3A31D6F-FD44-9425-0610-3718BBEB354F",
          name: "二级",
          parent_id: "0",
          sort: 2,
          type: "ALARMLEVEL",
          value: "2"
      },
      {
          children: [],
          description: "报警等级（三级）",
          id: "0C97BEB5-05B7-B935-BF86-EAC3CF8B3C45",
          name: "三级",
          parent_id: "0",
          sort: 3,
          type: "ALARMLEVEL",
          value: "3"
      },
      {
          children: [],
          description: "报警等级（四级）",
          id: "EF2E56C7-1A04-084B-8034-41852E41523C",
          name: "四级",
          parent_id: "0",
          sort: 4,
          type: "ALARMLEVEL",
          value: "4"
      },
      {
          children: [],
          description: "报警等级（五级）",
          id: "0CAD6CD8-1433-6FB1-EB15-39E88FB0421F",
          name: "五级",
          parent_id: "0",
          sort: 5,
          type: "ALARMLEVEL",
          value: "5"
      }
  ]
  },
  async addBase(item) {
    var param = {
      captureId: item.id,
      tableIds: this.VideoPhotoData.selectWhites.length > 0 ? this.VideoPhotoData.selectWhites : this.VideoPhotoData.selectBlacks
    }
    const rsp = await addToBase(param)
    return rsp
  }
  },
  watch:{
    
  }
}
